<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-wrap align-end benben-position-layout flex myCourse_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub myCourse_fd0_0'>
					<view class='flex align-center myCourse_fd0_0_c0'>
					</view>
					<text class='myCourse_fd0_0_c1'>我的课程</text>
					<view class='flex align-center justify-end myCourse_fd0_0_c0'>
						<text v-if="current == 2 && !isEdit" @tap.stop="bianji">编辑</text>
						<text v-if="current == 2 && isEdit" @tap.stop="bianji">关闭</text>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			
			<!---flex布局flex布局开始-->
			<view class="tabs_info">
				<u-tabs bg-color="transparent" :list="tabList" :bar-style="barStyle" name="short_name" active-color="#101010" bar-width="40" bar-height="6" :is-scroll="false" inactive-color="#969696" font-size="30" gutter="10" :current="current" @change="change"></u-tabs>
			</view>

			<view class="loading_css" v-if="isShow">
				<u-loading size="36" color="#3090FF"></u-loading>
				<view>加载中</view>
			</view>
			<template v-else>
				<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout myCourse_flex_5">
					<view class='flex align-stretch myCourse_fd5_0' v-for="(item,index) in list" :key="index">
						<view class='flex flex-wrap align-center myCourse_fd5_0_c0' v-if="isEdit" @tap.stop="selectEdit(item.course_id, index)">
							<image v-if="item.isSelect" class='myCourse_fd5_0_c0_c0' mode="aspectFill" :src='STATIC_URL+"3.png"'></image>
							<image v-else class='myCourse_fd5_0_c0_c0' mode="aspectFill" :src='STATIC_URL+"135.png"'></image>
						</view>
						<template v-if="current == 0">
							<view class='flex' style="width: 100%;" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/sy/courseCatalog/courseCatalog?id=${item.course_id}`">
								<view class='flex flex-wrap align-center myCourse_fd5_0_c1_c0'>
									<u-lazy-load :image="item.thumb" border-radius="16" height="200" img-mode="aspectFill"></u-lazy-load>
								</view>
								<view>
									<view class='flex flex-wrap' style="padding-top: 12rpx;">
										<text class='myCourse_fd5_0_c1_c1_c0_c0'>{{item.title}}</text>
									</view>
									<view class='flex myCourse_fd5_0_c1_c1_c1'>
										<text class='myCourse_fd5_0_c1_c1_c1_c0'>{{item.synopsis}}</text>
									</view>
								</view>
							</view>
						</template>
						<template v-if="current == 1">
							<view class='flex' @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/sy/courseDetails/courseDetails?aid=${item.course_id}`">
								<view class='flex flex-wrap align-center myCourse_fd5_0_c1_c0'>
									<u-lazy-load :image="item.thumb" border-radius="16" height="200" img-mode="aspectFill"></u-lazy-load>
								</view>
								<view>
									<view class='flex flex-wrap' style="padding-top: 12rpx;">
										<text class='myCourse_fd5_0_c1_c1_c0_c0'>{{item.title}}</text>
									</view>
									<view class='flex myCourse_fd5_0_c1_c1_c1'>
										<text class='myCourse_fd5_0_c1_c1_c1_c0'>{{item.synopsis}}</text>
									</view>
								</view>
							</view>
						</template>
						<template v-if="current == 2">
							<view class='flex' @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/sy/courseCatalog/downloadChapter?id=${item.course_id}`">
								<view class='flex flex-wrap align-center myCourse_fd5_0_c1_c0' >
									<u-lazy-load :image="item.thumb" border-radius="16" height="200" img-mode="aspectFill"></u-lazy-load>
								</view>
								<view>
									<view class='flex flex-wrap' style="padding-top: 12rpx;">
										<text class='myCourse_fd5_0_c1_c1_c0_c0'>{{item.title}}</text>
									</view>
									<view class='flex myCourse_fd5_0_c1_c1_c1'>
										<text class='myCourse_fd5_0_c1_c1_c1_c0'>{{item.synopsis}}</text>
									</view>
								</view>
							</view>
						</template>
						
					</view>
				</view>
				<view class="noData" v-if="list.length == 0 && !isShow">
					<image :src='STATIC_URL+"no.png"'></image>
				</view>
				
				<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout" v-if="current == 2 && isEdit">
					<view class='flex flex-wrap align-center justify-between myCourse_fd1_0'>
						<view class='flex flex-wrap align-center' @tap.stop="selectTotal">
							<image v-if="isTotal" class='myCourse_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
							<image v-else class='myCourse_fd1_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"135.png"'></image>
							<text class='myCourse_fd1_0_c0_c2'>全选</text>
						</view>
						<view class='flex flex-wrap align-center justify-center myCourse_fd1_0_c1' @tap.stop="deleteCache">
							<text class='self-center myCourse_fd1_0_c1_c0'>删除</text>
						</view>
					</view>
				</view>
				<view style="height: 100rpx;" v-if="current == 2 && isEdit"></view>
			</template>
			
			
			<!---flex布局flex布局结束-->
			<benben-popup v-model="popupShow1702371418499" :mask="true" :mask-close-able="false" mode='center'>
				<!---清除本地缓存flex布局开始-->
				<view class="flex benben-flex-layout flex-wrap align-center">
					<view class='flex flex-direction flex-wrap align-center myCourse_fd2_0'>
						<text class='myCourse_fd2_0_c0'>提示</text>
						<text class='myCourse_fd2_0_c1'>确定删除该文件下所有视频？</text>
						<view class='flex align-center myCourse_fd2_0_c2'>
							<button class='myCourse_fd2_0_c2_c0' @tap.stop="popupShow1702371418499=false">取消</button>
							<button class='myCourse_fd2_0_c2_c1' @tap.stop="confirmDel">确认</button>
						</view>
					</view>
				</view>
			
				<!---清除本地缓存flex布局结束-->
			
			</benben-popup>
		</view>
	</view>
</template>
<script>
	export default {
		components: {},


		data() {
			return {
				"tabsInfofd3_0": {
					lineleft: '',
					lineWidth: '',
					moveX: 0,
					scrollX: 0,
					PageScrollX: 0
				},
				"popupShow1702371418499": false,
				"tabs": 1,

				current: 0,
				barStyle: {
					backgroundColor: '#3090FF'
				},
				tabList: [{
					name: '待完成'
				},{
					name: '已完成'
				},{
					name: '我的缓存'
				}],
				
				
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
				"isEdit": false,
				"isTotal": false,
				
				"saveFileList": [],  // 缓存的文件列表
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			// this.getList();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			if (this.current == 0 || this.current == 1) {
				this.getList();
			} else if (this.current == 2) {
				this.getCache();
			}
			this.saveFileList = uni.getStorageSync('saveFileList');
		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			if (this.current == 0 || this.current == 1) {
				this.getList();
			} else if (this.current == 2) {
				this.getCache();
			}
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				if (this.current == 0 || this.current == 1) {
					this.getList();
				} else if (this.current == 2) {
					this.getCache();
				}
				
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			change(index) {
				this.current = index;
				if (index == 0 || index == 1) {
					this.isEdit = false;
					this.isTotal = false;
					
					this.page = 1;
					this.is_pull = true;
					this.isShow = true;
					this.getList();
				} else if (index == 2) {
					this.page = 1;
					this.is_pull = true;
					this.isShow = true;
					this.getCache();
				}
			},
			// 我的课程  post6585800d455a5
			getList() {
				this.$api.post(global.apiUrls.post6585800d455a5, {
					status: this.current + 1,
					page: this.page
				}).then(res => {
					uni.stopPullDownRefresh();
					this.isShow = false;
					// console.log(res);
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						if (this.is_pull) {
							this.list = res.data.data.data;
						} else {
							this.list = this.list.concat(res.data.data.data);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 获取我的缓存  post6585827565d89
			getCache() {
				this.$api.post(global.apiUrls.post6585827565d89, {
					page: this.page
				}).then(res => {
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						if (res.data.data.data.length > 0) {
							res.data.data.data.forEach((v, k) => {
								v.isSelect = false;
							})
						}
						if (this.is_pull) {
							this.list = res.data.data.data;
						} else {
							this.list = this.list.concat(res.data.data.data);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			selectEdit(id, index) {
				this.list[index].isSelect = !this.list[index].isSelect;
				let num = this.list.filter(item => !item.isSelect).length;
				if (num != 0) {
					this.isTotal = false;
				} else {
					this.isTotal = true;
				}
			},
			bianji() {
				this.isEdit = !this.isEdit;
			},
			selectTotal() {
				if (this.list.length == 0) return;
				this.isTotal = !this.isTotal;
				if (this.isTotal) {
					this.list.forEach((v, k) => {
						v.isSelect = true;
					})
				} else {
					this.list.forEach((v, k) => {
						v.isSelect = false;
					})
				}
			},
			// 删除缓存
			deleteCache() {
				let num = this.list.filter(item => item.isSelect).length;
				if (num == 0) {
					this.$message.info('请选择删除的课程');
					return;
				}
				this.popupShow1702371418499 = true;
			},
			// 确定删除  post658582e7898b7
			confirmDel() {
				this.popupShow1702371418499 = false;
				let course_id = [];
				this.list.forEach((v, k) => {
					if (v.isSelect) {
						course_id.push(v.course_id);
					}
				})
				this.$api.post(global.apiUrls.post658582e7898b7, {
					course_id: course_id.join(',')
				}).then(res => {
					this.$message.info(res.data.msg);
					if (res.data.code == 1) {
						this.isEdit = false;
						this.isTotal = false;
						this.page = 1;
						this.is_pull = true;
						this.isShow = true;
						this.getCache();
						
						// 删除缓存中的数据
						this.saveFileList.forEach((v, k) => {
							course_id.forEach((v1, k1) => {
								if (v1 == v.course_id) {
									this.saveFileList.splice(k, 1);
								}
							})
						})
						if (this.saveFileList.length == 0) {
							this.saveFileList = "";
						}
						uni.setStorageSync('saveFileList', this.saveFileList);
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.tabs_info {
		width: 100%;
		position: fixed;
		z-index: 10;
		padding: 0 24rpx;
		height: 80rpx;
		background: #FFFFFF;
		// border-bottom: 1rpx solid #eee;
	}
	
	/deep/.u-lazy-item {
		width: 260rpx !important;
		height: 200rpx !important;
	}
	
	
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #FFFFFF;
		background-size: 100% auto;
	}

	.myCourse_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.myCourse_fd0_0_c1 {
		color: #333;
		font-size: 36rpx;
		font-weight: 700;
	}

	.myCourse_fd0_0_c0 {
		width: 120rpx;
		height: 88rpx;
	}

	.myCourse_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		height: 88rpx;
	}

	.myCourse_fd1_0_c1_c0 {
		font-size: 32rpx;
		color: var(--benbenFontColor3);
	}

	.myCourse_fd1_0_c1 {
		background: #FF5050;
		line-height: 98rpx;
		width: 232rpx;
		height: 98rpx;
		background-size: 100% auto;
	}

	.myCourse_fd1_0_c0_c2 {
		font-size: 26rpx;
		color: rgba(150, 150, 150, 1);
		margin: 0rpx 0rpx 0rpx 16rpx;
	}

	.myCourse_fd1_0_c0_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.myCourse_fd1_0 {
		padding: 0rpx 0rpx 0rpx 32rpx;
		width: 100%;
		height: 98rpx;
		position: fixed;
		bottom: calc(0rpx + var(--window-bottom));
		box-shadow: 0px -3rpx 6rpx 1px rgba(0,0,0,0.07);
	}

	.myCourse_fd2_0_c2_c1 {
		background: var(--benbenbgColor1);
		font-size: 32rpx;
		color: var(--benbenFontColor4);
		width: 270rpx;
		height: 101rpx;
		line-height: 101rpx;
		font-weight: 500;
	}

	.myCourse_fd2_0_c2_c0 {
		border-right: 1px solid #eee;
		background: #fff;
		font-size: 32rpx;
		color: rgba(153, 153, 153, 1);
		width: 270rpx;
		height: 101rpx;
		line-height: 101rpx;
		font-weight: 400;
	}

	.myCourse_fd2_0_c2 {
		border-top: 1px solid #eee;
		margin: 51rpx 0rpx 0rpx 0rpx;
	}

	.myCourse_fd2_0_c1 {
		line-height: 44rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #333333;
		text-align: center;
		margin: 32rpx 40rpx 0rpx 40rpx;
	}

	.myCourse_fd2_0_c0 {
		line-height: 44rpx;
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.myCourse_fd2_0 {
		background: #fff;
		width: 540rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.myCourse_linefd3_0 {
		background: var(--benbenbgColor0);
		width: 40rpx;
		height: 6rpx;
		top: 80rpx;
		background-size: 100% auto !important;
	}

	.checkTitlefd3_0 {
		font-weight: 700 !important;
		font-size: 32rpx !important;
		color: #333 !important;
		background-color: rgba(255, 255, 255, 1) !important;
	}

	::v-deep .myCourse_benbenTabsfd3_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 90rpx;
		white-space: nowrap;
		text-align: center;
		font-size: 28rpx;
		color: rgba(150, 150, 150, 1);
	}

	.myCourse_flex_5 {
		padding: 80rpx 30rpx 0rpx 30rpx;
	}

	.myCourse_fd5_0_c1_c1_c1_c0 {
		-webkit-line-clamp: 3;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		font-size: 24rpx;
		color: rgba(167, 166, 167, 1);
	}

	.myCourse_fd5_0_c1_c1_c1 {
		margin: 12rpx 0rpx 0rpx 0rpx;
	}

	.myCourse_fd5_0_c1_c1_c0_c0 {
		font-size: 32rpx;
		color: rgba(51, 51, 51, 1);
		font-weight: 700;
	}

	.myCourse_fd5_0_c1_c0_c0 {
		width: 260rpx;
		height: 200rpx;
		border-radius: 16rpx;
	}

	.myCourse_fd5_0_c1_c0 {
		margin: 0rpx 24rpx 0rpx 0rpx;
	}

	.myCourse_fd5_0_c0_c0 {
		width: 36rpx;
		height: 36rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.myCourse_fd5_0_c0 {
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.myCourse_fd5_0 {
		margin: 20rpx 0rpx 20rpx 0rpx;
	}
</style>